Skip to content

🔒 Fix DOM-based XSS in InvestAI.html Rendering#2

Open
FelipeDupas wants to merge 1 commit intomainfrom
security-fix-dom-xss-5767870438976296475
Open

🔒 Fix DOM-based XSS in InvestAI.html Rendering#2
FelipeDupas wants to merge 1 commit intomainfrom
security-fix-dom-xss-5767870438976296475

Conversation

@FelipeDupas
Copy link
Owner

This PR fixes a critical security vulnerability where user-controlled or AI-generated data was being rendered directly into the DOM using innerHTML, potentially allowing for Cross-Site Scripting (XSS) attacks.

🎯 What:

I've implemented a robust HTML escaping mechanism within InvestAI.html and applied it to all dynamic data rendering points.

⚠️ Risk:

Previously, an attacker could potentially inject malicious scripts through portfolio item names, tickers, or even by manipulating AI responses if they could influence the analysis engine. This could lead to unauthorized actions on behalf of the user or theft of sensitive session information.

🛡️ Solution:

  1. Added a central esc(str) function that converts HTML special characters into their respective entities.
  2. Refactored all instances of innerHTML interpolation to wrap dynamic data in esc().
  3. Verified the fix through both automated unit testing of the escaping logic and end-to-end browser testing using Playwright to ensure malicious payloads are safely rendered as text.

PR created automatically by Jules for task 5767870438976296475 started by @FelipeDupas

This commit addresses several DOM-based XSS vulnerabilities in the `InvestAI.html` file. The core fix involves:
- Introducing a helper function `esc(str)` to escape HTML entities (`&`, `<`, `>`, `"`, `'`).
- Applying `esc()` to all dynamic data interpolated into `innerHTML` sinks, including:
    - Portfolio data (tickers, asset names, comments, dates).
    - AI-generated analysis text and summaries.
    - Error messages in the `runAnalysis` function.
    - User profile labels (Risk and Horizon).

These changes ensure that untrusted input from the user or the AI analysis is rendered as plain text, preventing malicious script execution in the browser.

Verification:
- Logic verified with Node.js unit tests (`verify_fix.js`).
- Frontend verified with Playwright (`verify_xss_fix.py`), confirming that injected HTML tags are correctly escaped in the DOM.

Co-authored-by: FelipeDupas <118365943+FelipeDupas@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant